from django.contrib.auth.models import User
from django.db import models

# Create your models here.
class Topic(models.Model):
    '''  用户学习的主题    '''
    text=models.CharField(max_length=200)                       ## 存储文本内容
    data_added=models.DateTimeField(auto_now_add=True)          ### 自动设置模型时间
    owner=models.ForeignKey(User,on_delete=models.CASCADE)
    def __str__(self):
        '''返回model字符串表示'''
        return self.text
        # return "Fuck"


class Entry(models.Model):
    '''学校主题的某个知识'''
    topic =models.ForeignKey(Topic,on_delete=models.CASCADE)
    text=models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)


    class Meta:
        verbose_name_plural='entries'

    def __str__(self):
        ''' 返回model字符串表示 '''
        return  self.text[:50]+"...."